package com.mbigger.admin.common;

import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

@ControllerAdvice
public class ResponseAdvice implements ResponseBodyAdvice<Object> {
	
	private static final String METHOD_NAME = "handleException";

	@Override
	public Object beforeBodyWrite(Object returnVlaue, MethodParameter methodParameter, MediaType mediaType,
			Class<? extends HttpMessageConverter<?>> clazz, ServerHttpRequest request, ServerHttpResponse response) {
		return JsonResultHoler.success(returnVlaue).toMap();
	}

	@Override
	public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> clazz) {
		if(METHOD_NAME.equals(methodParameter.getMethod().getName())) {
			return false;
		}else {
			return true;
		}
	}

}
